package net.oschina.app.com.testcase.others;

import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.robotium.solo.Solo;

import net.oschina.app.AppStart;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/1/23.
 */

public class HelloWorld extends ActivityInstrumentationTestCase2 {
    private Solo solo;

    public HelloWorld() {

        super(AppStart.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());

    }

    public void testName() throws Exception {
        solo.clickOnText("我的");
        solo.sleep(5000);
        solo.clickOnText("点击头像登录");
        solo.sleep(5000);
        //根据索引找到控件，第1个文本输入框，并且在文本框中输入内容
        solo.enterText(0, "HelloWorld");
        solo.sleep(5000);
        //先找到控件，根据控件在文本框中输入内容
        EditText editText = solo.getEditText(1);
        solo.enterText(editText, "nice too me you");
        solo.sleep(5000);

        //点击登录按钮
        solo.clickOnButton("登录");
        //打印日志输出是否找到登录按钮
        Log.i("auto", "登录按钮找到了");
        solo.sleep(5000);
        //返回上一层页面
        solo.goBack();
        solo.clickOnText("发现");
        solo.sleep(3000);
        solo.clickOnText("找人");
        //在第一个文本输入框中输入内容
        solo.enterText(0, "我");
        solo.sleep(5000);
        //在系统键盘中按回车键进行搜索
        solo.sendKey(KeyEvent.KEYCODE_ENTER);//KeyEvent.KEYCODE_ENTER代表点击安卓设备键盘中的回车键
        solo.sleep(5000);
    }

    public void testName2() throws Exception {
        solo.sleep(5000);
        //根据id定位控件
        View view = solo.getView("net.oschina.app:id/tv_title", 1);
        //获取控件的宽
        int width = view.getWidth();
        //获取控件的高
        int height = view.getHeight();
        //获取x坐标的宽
        int x = width / 2;
        //定义二维数组，元素存储的是xy坐标
        int[] xy=new int[2];
        //获取控件的xy坐标值
        view.getLocationOnScreen(xy);
        //得到y坐标值
        int y= xy[1]+height/2;
        //按照坐标点击
        solo.clickOnScreen(x,y);
        solo.sleep(10000);
    }

    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
        super.tearDown();


    }
}
